package com.dyh.quickdemo.demos.spy;

/*
@Author=Joey Wheeler
@Date=2020/12/4 9:44
*/
public class Spy {

    public String lineMsg;
    public String methodName;
    public String fullInfo;

    public static void around(Runnable r){
        Spy.enter(3);//这个多套了一层
        r.run();
        Spy.exit();
    }

    public static void enter(int idx){
        Spy spy = new Spy();
        StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
        /*1 是 com.dyh.quickdemo.demos.spy.Spy.<init>*/
        StackTraceElement element = stackTraceElements[idx];
        spy.lineMsg =element.toString();
        spy.methodName = String.format("%s#%s",
                element.getClassName(),element.getMethodName());
        spy.fullInfo = element.toString();
        SpyCenter.addSpy(spy);//注册
        SpyContextFacade.add(spy);
    }

    public static void enter(){
        enter(3);//一般来说就是3 enter(本身是3)
    }

    public static void exit(){
        SpyContextFacade.report();
       // SpyContextFacade.clean();
    }

}
